﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using eBook.Core.Contracts;
using eBook.Core.BusinessObjects;
using System.Reflection;
using WeifenLuo.WinFormsUI.Docking;


namespace eBook.WinApp
{
  
  public partial class frmBook : DockContent
  {
    private ILibRepository _libRepository;

    public frmBook()
    {
      InitializeComponent();
    }

    public frmBook(ILibRepository libRepository) : this()
    {
      _libRepository = libRepository;
    }


    private void btnFetch_Click(object sender, EventArgs e)
    {
      this.Cursor = Cursors.WaitCursor;
      try 
	    {
        var list = _libRepository.GetBookList();
        var bs = new SortableBindingList<boBookListItem>(list);
        bsList.DataSource = bs;

        bsList.ResetBindings(false);
	    }
	    finally
	    {
        this.Cursor = Cursors.Default;
      }    
    }

    private void grdList_DoubleClick(object sender, EventArgs e)
    {
      var item = bsList.Current as boBookListItem;
      var detail = FormFactory.Instance.LaunchDockContent<frmBookDetail>(allowMultipleInstance:true) as frmBookDetail;
      detail.RenderBookDetail(item.BookId);
    }






  }

}
